package com.tql.kingdee.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.tql.kingdee.bean.TqlStapPriceBean;
import com.tql.kingdee.mapper.DsTestMapper;
import com.tql.kingdee.response.MaterialIncaseResponse;
import com.tql.kingdee.response.MaterialPurchaseResponse;
import com.tql.kingdee.response.MaterialTransferoutResponse;
import com.tql.kingdee.util.CommonUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhengcl
 * @since 1.0.0
 */
@Service
public class DsTestServiceImpl implements DsTestService{

    @Autowired
    private DsTestMapper dsTestMapper;

//    @Autowired
//    private MaterialIncaseService materialIncaseService;
//
//    @Autowired
//    private MaterialPurchaseService materialPurchaseService;
//
//    @Autowired
//    private MaterialTransferService materialTransferService;

    @Override
    public int selectSlaveAndInsert() {
        int count = dsTestMapper.selectCount();
        return count;
    }

    @Override
    public void batchAddIncase(List<MaterialIncaseResponse> list, String inChangeTabName, int type) {
        dsTestMapper.batchAddIncase(list,inChangeTabName,type);
    }

    @Override
    public void batchAddPurchase(List<MaterialPurchaseResponse> list, String inChangeTabName, int type) {
        dsTestMapper.batchAddPurchase(list,inChangeTabName,type);
    }

    @Override
    public void batchAddTransferoutIn(List<MaterialTransferoutResponse> list, String inChangeTabName, int type) {
        dsTestMapper.batchAddTransferoutOut(list,inChangeTabName,type);
    }

    @Override
    public void batchAddTransferoutOut(List<MaterialTransferoutResponse> list, String inChangeTabName, int type) {
        if(CollectionUtils.isEmpty(list))return ;
        dsTestMapper.batchAddTransferoutOut(list,inChangeTabName,type);
    }

    @Override
    public TqlStapPriceBean getTqlStapPrice(String fMaterialIdfnumber) {
        return dsTestMapper.getTqlStapPrice(fMaterialIdfnumber);
    }

//    @Override
//    @Transactional
//    public int init() {
//        int count = 0;
//        for (int i = 1; i <= 12; i++) {
//            String inChangeTabName = CommonUtil.TQL_STAP_IN_CHANGE+i;
//
//            String tabname1 = CommonUtil.TABLENAME_TQL_MATARIAL_INCASE+i;
//            List<MaterialIncaseResponse> list1 = materialIncaseService.selectList(tabname1);
//            if (!list1.isEmpty()) {
//                dsTestMapper.batchAddIncase(list1, inChangeTabName, 1);
//                count = count + list1.size();
//            }
//
//            String tabname2 = CommonUtil.TABLENAME_TQL_MATARIAL_PURCHASE+i;
//            List<MaterialPurchaseResponse> list2 = materialPurchaseService.selectList(tabname2);
//            if (!list2.isEmpty()) {
//                dsTestMapper.batchAddPurchase(list2, inChangeTabName,2);
//                count = count + list2.size();
//            }
//
//            String tabname3 = CommonUtil.TABLENAME_TQL_KINGDEE_TRANSFER+i;
//            List<MaterialTransferoutResponse> list3 = materialTransferService.selectList(tabname3);
//            if (!list3.isEmpty()) {
//                List<MaterialTransferoutResponse> list3In = list3.stream().filter(x->x.getFlag().equals("1")).collect(Collectors.toList());
//                dsTestMapper.batchAddTransferoutIn(list3In, inChangeTabName,3);
//            }
//
//            List<MaterialTransferoutResponse> list3Out = list3.stream().filter(x->x.getFlag().equals("-1")).collect(Collectors.toList());
//            if (!list3Out.isEmpty()) {
//                dsTestMapper.batchAddTransferoutOut(list3Out, inChangeTabName,4);
//                count = count+ list3.size();
//            }
//        }
//        return count;
//    }
}
